<?php
// +----------------------------------------------------------------------
// | Author: weifashi <605403358@qq.com>
// +----------------------------------------------------------------------	

use think\Request;
use think\facade\View;
use think\facade\Route;
use app\admin\model\SystemUpload;
use app\admin\model\SystemParamValue;
use app\admin\service\Nav as NavService;

//---------------------------
//---------后台入口--------
//---------------------------
if( !function_exists('views')  ){
	function views(Request $request) {

		//路径
		$url = $request->pathinfo();
		if(!$url || $url == 'views' || $url == 'views/'){ $url = "views/modules/index/index"; }
		$url = str_replace("views/","",$url);

		//赋值变量
		View::assign('navTpl', (new NavService)->getNavTpl($request->userInfo,$url) );
		View::assign('userInfo', $request->userInfo );
		View::assign('userAction',  json_encode($request->userAction));
		View::assign('isAccordionNav', 
			(new SystemParamValue)->getTextParamValue('系统参数','base_is_accordion_nav')
		);
		
		View::assign('userImg', '/'.
			( SystemUpload::where('file_buss_type','用户信息')
			->where('file_type','头像')
			->where('file_guid',$request->userInfo['user_guid'])
			->value("file_path") ?: 'admins/images/user_img.jpg')
		);

		//输出视图
		return View::fetch($url);
	};
};

Route::get('/', function(Request $request){ 
	return views($request);
});

Route::get('/views', function(Request $request){ 
	return views($request);
});

